//CHECKSTYLE:OFF

package com.ractoc.opengamefinder.server.translators;

import java.util.Map;
import java.util.LinkedHashMap;
/**
 * Main translator class. Only has one method, translate.
 * @author Mark Schrijver
 * @version 1.0
 */
public final class TranslatorMap {

    private static Map <String, Translator> translatorsByKey = new LinkedHashMap <String, Translator>();

    static {
        translatorsByKey.put("com.ractoc.opengamefinder.dao.AccountDAO",
                        new com.ractoc.opengamefinder.server.translators.TranslateAccountDAOToAccountVO());
        translatorsByKey.put("com.ractoc.opengamefinder.api.vo.AccountVO",
                        new com.ractoc.opengamefinder.server.translators.TranslateAccountVOToAccountDAO());
        translatorsByKey.put("com.ractoc.opengamefinder.dao.AvatarDAO",
                        new com.ractoc.opengamefinder.server.translators.TranslateAvatarDAOToAvatarVO());
        translatorsByKey.put("com.ractoc.opengamefinder.api.vo.AvatarVO",
                        new com.ractoc.opengamefinder.server.translators.TranslateAvatarVOToAvatarDAO());
    }

    /**
     * Constructor.
     */
    private TranslatorMap() {
    }

    /**
     * Selects the correct translator and uses that translator to translate the supplied message.
     * Only one translator is possible per bean class.
     * If no translator is available null is returned.
     * @param beanToTranslate the bean that needs to be translated.
     * @return the translated bean or null if no translator was available.
     */
    public static Object translate(final Object beanToTranslate) {
        Object result = null;
        if (beanToTranslate != null) {
            final Translator translator = translatorsByKey.get(beanToTranslate.getClass().getName());
            if (translator != null) {
                result = translator.translate(beanToTranslate);
            }
        }
        return result;
    }
}

//CHECKSTYLE:ONFF

